#include <iostream>
#include <queue>

using namespace std;
// 933. 最近的请求次数
// 写一个 RecentCounter 类来计算特定时间范围内最近的请求。
// 解释：
//RecentCounter recentCounter = new RecentCounter();
//recentCounter.ping(1);     // requests = [1]，范围是 [-2999,1]，返回 1
//recentCounter.ping(100);   // requests = [1, 100]，范围是 [-2900,100]，返回 2
//recentCounter.ping(3001);  // requests = [1, 100, 3001]，范围是 [1,3001]，返回 3
//recentCounter.ping(3002);  // requests = [1, 100, 3001, 3002]，范围是 [2,3002]，返回 3

class RecentCounter {
    queue<int> q;
    int count;  // 计数器，记录在 [t-3000, t] 内发生的请求数
public:
    RecentCounter() {
//        count = 0;
    }

    int ping(int t) {
        q.push(t);
//        count++;
        while(t - 3000 > q.front()) {   // 这里是while，不是if
            q.pop();
//            count--;
        }
        return q.size();
    }
};

int main() {
    RecentCounter recentCounter;
    cout << recentCounter.ping(1) << endl;     // requests = [1]，范围是 [-2999,1]，返回 1
    cout << recentCounter.ping(100) << endl;   // requests = [1, 100]，范围是 [-2900,100]，返回 2
    cout << recentCounter.ping(3001) << endl;  // requests = [1, 100, 3001]，范围是 [1,3001]，返回 3
    cout << recentCounter.ping(3002) << endl;  // requests = [1, 100, 3001, 3002]，范围是 [2,3002]，返回 3

    cout << endl;

    cout << recentCounter.ping(642) << endl;     // requests = [642]，范围是 [-2358,642]，返回 1
    cout << recentCounter.ping(1849) << endl;   // requests = [642, 1849]，范围是 [-1151,1849]，返回 2
    cout << recentCounter.ping(4921) << endl;  // requests = [4921]，范围是 [1921,4921]，返回 1 -- 返回错误(2)
    cout << recentCounter.ping(5936) << endl;  // requests = [4921,5936]，范围是 [2936,5936]，返回 2
    cout << recentCounter.ping(5957) << endl;  // requests = [4921,5936,5957]，范围是 [2957,5957]，返回 3

    return 0;
}
